package panel;


import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

public class PanelRuler extends JPanel {

	private static final long serialVersionUID = 1L;

	private String[] labels = null;

	private int leftPos = 50;

	public PanelRuler() {
		// super();
		// initialize();
	}

//	private void initialize() {
//		// this.setSize(new Dimension(193, 88));
//		// this.setPreferredSize(new Dimension(100,100));
//	}

	public PanelRuler(String[] labels) {
		// super();
		this.labels = labels;
	}

	public int selectedClassLabels = 0;

	public void paint(Graphics g) {
		// System.out.println("n:"+selectedClassLabels);
		int n = labels.length;
		int left = leftPos;
		int top = 1;
		int delta = (getWidth() - 40) / n;
		g.setColor(Color.white);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(Color.yellow);
		g.fillRect(left, 0, delta * n, 40);
		g.setColor(Color.blue);
		g.fillRect(left, 0, delta * selectedClassLabels, 40);
		g.setColor(Color.red);
		int k=0;
		for (int i = 0; i < n; i++) {
			if (i < selectedClassLabels) {
				g.setColor(Color.yellow);
			} else {
				g.setColor(Color.red);
			}
			if (k==0) {				
				g.drawString(labels[i], left + delta * i, top + 15+k);
				k=15;
			} else {
				g.drawString(labels[i], left + delta * i, top + 15+k);
				k=0;				
			}
			
		}
	}

	public void setLeftPos(int i) {
		// TODO Auto-generated method stub
		this.leftPos = i;
	}

	public void setSelectedClassLabels(int n) {
		selectedClassLabels = n + 1;
		this.updateUI();

	}

} 